package com.sardine.base.utils;

import java.io.UnsupportedEncodingException;

/**
 * 上海京东到家元信信息技术有限公司<br>
 * Created with IntelliJ IDEA.
 * Date:2017/6/9
 * Time:17:41
 * java 正则表达式验证
 *
 * @author daifeng<br>
 *         daifeng@imdada.cn
 * @since JDK 1.7 <br>
 * Copyright (c) 2017 imdada System Incorporated All Rights Reserved.
 */
public class EncodingUtils {

    /**
     * 转换其他编码字符串为UTF-8编码
     * @param src
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String convert2Utf8(String src) throws UnsupportedEncodingException {
        if (src.equals(new String(src.getBytes("iso8859-1"), "iso8859-1"))) {
            return new String(src.getBytes("iso8859-1"), "utf-8");
        } else if (src.equals(new String(src.getBytes("gbk"), "iso8859-1"))) {
            return new String(src.getBytes("gbk"), "utf-8");
        }
        return src;
    }

}
